"use strict";

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    /**
     * Add altering commands here.
     *
     * Example:
     * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
     */
    const { INTEGER, STRING, DATE } = Sequelize;
    await queryInterface.createTable("banners", {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      title: { type: STRING(100), allowNull: false },
      image: { type: STRING(255), allowNull: false },
      link: { type: STRING(255), allowNull: true },
      sort: { type: INTEGER, defaultValue: 0 },
      status: { type: INTEGER, defaultValue: 1 }, // 1: 显示, 0: 隐藏
      created_at: {
        type: DATE,
        allowNull: false,
        defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
      },
      updated_at: {
        type: DATE,
        allowNull: false,
        defaultValue: Sequelize.literal(
          "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
        ),
      },
    });
  },

  async down(queryInterface) {
    /**
     * Add reverting commands here.
     *
     * Example:
     * await queryInterface.dropTable('users');
     */
    await queryInterface.dropTable("banners");
  },
};
